package com.arvin.service.serviceImpl;

import com.arvin.mapper.InterviewMapper;
import com.arvin.mapper.StudentMapper;
import com.arvin.pojo.Contest;
import com.arvin.pojo.Interview;
import com.arvin.pojo.IntvInfo;
import com.arvin.pojo.PageBean;
import com.arvin.service.InterviewService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Service
public class InterviewServiceImpl implements InterviewService {

    @Autowired
    private InterviewMapper interviewMapper;
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 获取面试信息
     * @param page
     * @param pageSize
     * @param studentId
     * @param intvDate
     * @param stuName
     * @param className
     * @param intvState
     * @param intvScore
     * @return
     */
    @Transactional
    public PageBean getIntvInfo(Integer page, Integer pageSize, String studentId,
                                LocalDate intvDate, String stuName,String className,
                                String intvState,Integer intvScore) {
        PageHelper.startPage(page,pageSize);
        List<IntvInfo> intvInfoList = interviewMapper.getIntvInfo(studentId,intvDate,stuName,className,intvState,intvScore);
        for (IntvInfo intvInfo: intvInfoList){
            List<Contest> list = studentMapper.findByStudentIdToContest(intvInfo.getStudentId());
            intvInfo.setContest(list);
        }
        Page<IntvInfo> intvInfoPage = (Page<IntvInfo>) intvInfoList;
        PageBean pageBean = new PageBean(intvInfoPage.getTotal(),intvInfoPage.getResult());
        return pageBean;
    }

    /**
     * 修改学生面试状态
     * @param intvId
     * @param intvState
     * @param intvScore
     */
    public void updateIntvState(Integer intvId, String intvState,Integer intvScore) {
        Interview interview = new Interview();
        interview.setIntvId(intvId);
        interview.setIntvState(intvState);
        interview.setIntvScore(intvScore);
        interviewMapper.updateIntvInfo(interview);
    }

    /**
     * 学生批量通过或不通过考面试
     * @param ids
     */
    @Override
    public void passByIntvIds(List<Integer> ids,String intvState) {
        interviewMapper.updateStateByIntvIds(ids,intvState);
    }
}
